package cn.dkdoo.blackhorse_transactional.mongo.api.service;

import cn.dkdoo.blackhorse_transactional.mongo.api.bean.vo.TestRequest;
import cn.dkdoo.blackhorse_transactional.mongo.api.bean.vo.TestResponse;
import cn.dkdoo.blackhorse_transactional.mongo.api.repository.MongodbRepository;
import cn.dkdoo.utils.annotation.DkdTransactional;
import cn.dkdoo.utils.entity.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Nicky.Tang on 2021/5/12 11:00 下午
 *
 * @since 02.12.10
 */
@Service
@DkdTransactional
public class MongodbService {

    @Autowired
    MongodbRepository mongodbRepository;
//    @Autowired
//    MongodbService mongodbServiceProxy;

    public BaseResponse testAddAndUpdate(TestRequest request) {
        TestResponse response = new TestResponse();
        mongodbRepository.add(request.getData());
        this.updateMulti(request);
        response.buildSuccess();
        return response;
    }

    public BaseResponse updateTwice(TestRequest request) {
        BaseResponse response = new BaseResponse();
        this.updateMulti(request);
        this.updateMulti(request);
        response.buildSuccess();
        return response;
    }

    public BaseResponse updateMulti(TestRequest request) {
        BaseResponse response = new BaseResponse();
        mongodbRepository.updateMulti(request.getData());
        mongodbRepository.updateMulti2(request.getData2());
        response.buildSuccess();
        return response;
    }

}
